# @Version        : 1.0
# @Update Time    : 2024/9/15 21:43
# @File           : dict_model.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息
from advanced_alchemy.base import BigIntAuditBase
from sqlalchemy import String, Integer, BigInteger, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship


class SysDictType(BigIntAuditBase):
    """
    字典类型表
    """

    __tablename__ = "sys_dict_type"
    __table_args__ = {"comment": "字典类型表"}

    dict_name: Mapped[str] = mapped_column(
        String(100), nullable=True, default="", comment="字典名称"
    )
    dict_type: Mapped[str] = mapped_column(
        String(100), nullable=True, default="", comment="字典类型"
    )
    status: Mapped[str] = mapped_column(
        String(1), nullable=True, default="1", comment="状态（1正常 2停用）"
    )
    remark: Mapped[str] = mapped_column(
        String(522), nullable=True, default="", comment="备注"
    )
    dict_datas: Mapped[set["SysDictData"]] = relationship()


class SysDictData(BigIntAuditBase):
    """
    字典数据表
    """

    __tablename__ = "sys_dict_data"
    __table_args__ = {"comment": "字典数据表"}

    dict_sort: Mapped[int] = mapped_column(
        Integer, nullable=True, default=0, comment="字典排序"
    )
    dict_label: Mapped[str] = mapped_column(
        String(100), nullable=True, default="", comment="字典标签"
    )
    dict_value: Mapped[str] = mapped_column(
        String(100), nullable=True, default="", comment="字典键值"
    )
    dict_type_id: Mapped[int] = mapped_column(
        BigInteger,
        ForeignKey("sys_dict_type.id", ondelete="CASCADE"),
        comment="字典类型ID",
    )
    is_default: Mapped[str] = mapped_column(
        String(1), nullable=True, default="N", comment="是否默认（Y是 N否）"
    )
    status: Mapped[str] = mapped_column(
        String(1), nullable=True, default="1", comment="状态（1正常 2停用）"
    )
    remark: Mapped[str | None] = mapped_column(String(500), default="", comment="备注")
